Parse escaped spaces in makefile dependencies
authorAlex Crichton <alex@alexcrichton.com>
Fri, 3 Oct 2014 01:37:27 +0000 (18:37 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 3 Oct 2014 14:54:03 +0000 (07:54 -0700)
This means that if a project has a file with a space in the name it will
properly have its freshness calculated as opposed to always having it as a
candidate to be rebuilt.

Closes #648

src/cargo/ops/cargo_rustc/fingerprint.rs
tests/test_cargo_compile.rs

index f1840da877dbf52e6d90b417c6876ffa46aa6311..c93a233640ffc12d43faf817b417bce5c07d3d5f 100644 (file)
@@ -240,8 +240,18 @@ fn calculate_target_fresh(pkg: &Package, dep_info: &Path) -> CargoResult<bool> {
     }));
     let deps = line.slice_from(pos + 2);
 
-    for file in deps.split(' ').map(|s| s.trim()).filter(|s| !s.is_empty()) {
-        match fs::stat(&pkg.get_root().join(file)) {
+    let mut deps = deps.split(' ').map(|s| s.trim()).filter(|s| !s.is_empty());
+    loop {
+        let mut file = match deps.next() {
+            Some(s) => s.to_string(),
+            None => break,
+        };
+        while file.as_slice().ends_with("\\") {
+            file.pop();
+            file.push(' ');
+            file.push_str(deps.next().unwrap())
+        }
+        match fs::stat(&pkg.get_root().join(file.as_slice())) {
             Ok(stat) if stat.modified <= mtime => {}
             Ok(stat) => {
                 debug!("stale: {} -- {} vs {}", file, stat.modified, mtime);
index 764e7524cd8963b04c8e67498522fd403030fafc..b0ff9d7165d60b025200cf424f37199d425c1c5b 100644 (file)
@@ -1643,3 +1643,22 @@ test!(dep_no_libs {
                        .with_stderr("\
 Package `bar v0.0.0 ([..])` has no library targets"));
 })
+
+test!(recompile_space_in_name {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.0"
+            authors = []
+
+            [lib]
+            name = "foo"
+            path = "src/my lib.rs"
+        "#)
+        .file("src/my lib.rs", "");
+    assert_that(foo.cargo_process("build"), execs().with_status(0));
+    foo.root().move_into_the_past().assert();
+    assert_that(foo.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0).with_stdout(""));
+})